package com.xky.example_student.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xky.example_student.entity.Student;
import com.xky.example_student.entity.Teacher;
import com.xky.example_student.service.TeacherService;
import com.xky.example_student.mapper.TeacherMapper;
import lombok.Getter;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

/**
 * @author adf01
 * @description 针对表【teacher】的数据库操作Service实现
 * @createDate 2025-08-05 14:18:33
 */
@Getter
@Service
public class TeacherServiceImpl extends ServiceImpl<TeacherMapper, Teacher>
        implements TeacherService {

    @Override
    public void saveTime1(Teacher teacher) {
        teacher.setCreateTime(LocalDateTime.now());
        teacher.setUpdateTime(LocalDateTime.now());
    }

    @Override
    public boolean saveWithTeaIdCheck(Teacher teacher) {

        QueryWrapper<Teacher> teacherQueryWrapper = new QueryWrapper<>();
        teacherQueryWrapper.eq("tea_id", teacher.getTeaId());
        Long count = baseMapper.selectCount(teacherQueryWrapper);

        if (count > 0) {
            return false;
        }

        return save(teacher);
    }

    @Override
    public boolean removeAll() {
        LambdaQueryWrapper<Teacher> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.select(Teacher::getId);
        List<Teacher> teachers = baseMapper.selectList(lambdaQueryWrapper);

        if (teachers.isEmpty()) {
            return true;
        }

        teachers.stream()
                .map(Teacher::getId)
                .toList();

        return removeByIds(teachers);
    }

}




